package com.cmse.web.listener;
/**
 * @author wulibin, exceptsky@gmail.com, 2012-3-9 下午1:33:35
 * 
 */
import java.util.Date;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.cmse.constant.GlobalConstants;
import com.cmse.persistence.domain.SiteInfo;
import com.cmse.service.ISiteInfoService;

public class StartupListener implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent event) {
		System.out.println("Your website is now starting and initializing... ");
		ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
		/*初始化站点信息*/
		
		ISiteInfoService siteInfoService = (ISiteInfoService)context.getBean("siteInfoService");
		SiteInfo siteInfo = siteInfoService.get();
		if(null == siteInfo){
			siteInfo = new SiteInfo();
			siteInfo.setTitle("深圳大学材料学院");
			siteInfo.setSubTitle("");
			siteInfo.setArticalAnonymousCommentOn(false);
			siteInfo.setArticalCommentOn(true);
			siteInfo.setCommentVerify(false);
			siteInfo.setDescription("深圳大学材料学院于2006年9月在原材料科学与工程系基础上成立。材料学院拥有一支素质较高的教师队伍和科研力量，现有教职工41人，其中教授12人(博士生导师4人)，副高职称15人，30人拥有博士学位。");
			siteInfo.setKeyWords("深圳大学,材料学院,深圳大学材料学院,深大,特区大学,Shenzhen University");
			siteInfo.setModifiedAt(new Date());
			siteInfoService.add(siteInfo);
		}
		event.getServletContext().setAttribute(GlobalConstants.ATTRIBUTE_SITEINFO, siteInfo);
		
	}

	@Override
	public void contextDestroyed(ServletContextEvent event) {
		// TODO Auto-generated method stub
	}
}
